package com.enniswu.weitter.setting.language;

import android.os.Bundle;
import android.widget.RadioGroup;

import com.enniswu.weitter.R;
import com.enniswu.weitter.base.BaseActivity;
import com.enniswu.weitter.data.local.SPSupport;
import com.enniswu.weitter.util.Utility;

import butterknife.BindView;

public class LanguageActivity extends BaseActivity implements RadioGroup.OnCheckedChangeListener {

    @BindView(R.id.rg_language)
    RadioGroup rgLanguage;
    private String language;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_language);
        setTitle(R.string.center_language);
        language = SPSupport.getInstance().getLanguage();
        rgLanguage.setOnCheckedChangeListener(this);
        switch (language) {
            case "zh":
                rgLanguage.check(R.id.rb_zh);
                break;
            case "en":
                rgLanguage.check(R.id.rb_en);
                break;
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_zh:
                setLanguage("zh");
                break;
            case R.id.rb_en:
                setLanguage("en");
                break;
        }
    }

    public void setLanguage(String language) {
        if (this.language.equals(language))
            return;
        Utility.setLanguage(this, language);
    }
}
